package com.fzz.serviceImpl;

import com.fzz.dao.ViewMapping;
import com.fzz.domain.View;
import com.fzz.service.ViewService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.ui.Model;

import java.util.List;

@Component
public class ViewServiceImpl implements ViewService {

    @Autowired
    private ViewMapping viewMapping;
    @Override
    public void addView(View view) {

        viewMapping.addView(view);
    }

    @Override
    public List<View> loadView() {
        return viewMapping.loadView();
    }

    @Override
    public PageInfo<View> selectViewWithPage(Model model, Integer page, Integer count) {
        PageHelper.startPage(page,count);
        List<View> viewWithPageList = viewMapping.selectViewWithPage();
        PageInfo<View> pageInfo=new PageInfo<>(viewWithPageList);
        model.addAttribute("pageInfo",pageInfo);
        return pageInfo;
    }

}
